package cn.afactory.tygz.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.harwkin.nb.camera.BaseImgView;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;

import java.util.ArrayList;
import java.util.List;

import cn.afactory.tygz.R;
import cn.afactory.tygz.common.Gendar;
import cn.afactory.tygz.model.MoneyShop;
import cn.afactory.tygz.model.SnsUserInfo;

/**
 *用户列表适配器
 */
public class MoneyShopAdapter extends BaseAdapter {
    private List<MoneyShop> mList = new ArrayList<MoneyShop>();
    private Context mContext;

    public MoneyShopAdapter(Context ctx, List<MoneyShop> list) {
        mList = list;
        mContext = ctx;
    }

    @Override
    public int getCount() {
        return mList != null ? mList.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return mList != null ? mList.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        final MoneyShop moneyShop = mList.get(position);
        if(convertView == null){
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_money_shop,null);
            holder.imageView = (ImageView) convertView.findViewById(R.id.imageView);
            holder.name = (TextView) convertView.findViewById(R.id.name);
            holder.money = (TextView) convertView.findViewById(R.id.money);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder)convertView.getTag();
        }

        holder.name.setText(moneyShop.name);
        BaseImgView.loadimg(holder.imageView, moneyShop.pic, R.drawable.ic_pic_loading_default_small,
                R.drawable.ic_pic_loading_default_small, R.drawable.ic_pic_loading_default_small, ImageScaleType.EXACTLY,
                (int) mContext.getResources().getDimension(R.dimen.forums_height),
                (int) mContext.getResources().getDimension(R.dimen.forums_height),
                0);
        holder.money.setText("金币:"+moneyShop.money+"");
        return convertView;
    }


    public void setDataChange(List<MoneyShop> list){

        this.mList = list;
        notifyDataSetChanged();
    }


    static class ViewHolder{
        public ImageView imageView;

        public TextView name;
        public TextView money;

    }
}